import nme.Assets;
import nme.display.Sprite;
import nme.display.Bitmap;
import nme.display.BitmapData;

import nme.geom.Rectangle;
import nme.geom.Matrix;
import nme.geom.Point;

class AnimData
{
	public var _id:String;
	public var _name:String;
	public var _frames_id:Array <String>;
	public var _frames_matrix:Array <Matrix>;
	public var _frames_loop_time:Array <Int>;
	// public var _frames_colorTranform:Array <String>;
	
	private function new (id:String, name:String)
	{
		_id = id;
		_name = name;
		_frames_id = new Array<String> ();
		_frames_matrix = new Array <Matrix> ();
		_frames_loop_time = new Array <Int> ();
	}
	
	private function readFrameData (frameXml:Xml):Void
	{
		_frames_id.push (frameXml.get("id"));
		_frames_matrix.push (
			new Matrix (
				Std.parseFloat (frameXml.get("a")),
				Std.parseFloat (frameXml.get("b")),
				Std.parseFloat (frameXml.get("c")),
				Std.parseFloat (frameXml.get("d")),
				Std.parseFloat (frameXml.get("tx")),
				Std.parseFloat (frameXml.get("ty"))
			)
		);
		_frames_loop_time.push (Std.parseInt (frameXml.get("time")));
	}
	
	public static function create (animXml:Xml):AnimData
	{
		var anim:AnimData = new AnimData (animXml.get("id"), animXml.get("name"));
		
		var frames:Iterator<Xml> = animXml.elementsNamed("frame");		
		for (f in frames) anim.readFrameData (f);
		
		return anim;
	}
}